<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>picasa.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_ui_media_picasa.js.html">picasa.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2009 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>
<a name="line16"></a>/**
<a name="line17"></a> * @fileoverview provides a reusable picasa album UI component given a public
<a name="line18"></a> * picasa album URL.
<a name="line19"></a> *
<a name="line20"></a> * TODO(user): implement the javascript viewer, for users without flash. Get it
<a name="line21"></a> * from the Gmail Picasa gadget.
<a name="line22"></a> *
<a name="line23"></a> * goog.ui.media.PicasaAlbum is actually a {@link goog.ui.ControlRenderer}, a
<a name="line24"></a> * stateless class - that could/should be used as a Singleton with the static
<a name="line25"></a> * method {@code goog.ui.media.PicasaAlbum.getInstance} -, that knows how to
<a name="line26"></a> * render picasa albums. It is designed to be used with a
<a name="line27"></a> * {@link goog.ui.Control}, which will actually control the media renderer and
<a name="line28"></a> * provide the {@link goog.ui.Component} base. This design guarantees that all
<a name="line29"></a> * different types of medias will behave alike but will look different.
<a name="line30"></a> *
<a name="line31"></a> * goog.ui.media.PicasaAlbum expects {@code goog.ui.media.PicasaAlbumModel}s on
<a name="line32"></a> * {@code goog.ui.Control.getModel} as data models, and render a flash object
<a name="line33"></a> * that will show a slideshow with the contents of that album URL.
<a name="line34"></a> *
<a name="line35"></a> * Example of usage:
<a name="line36"></a> *
<a name="line37"></a> * &lt;pre&gt;
<a name="line38"></a> *   var album = goog.ui.media.PicasaAlbumModel.newInstance(
<a name="line39"></a> *       &#39;http://picasaweb.google.com/username/SanFranciscoCalifornia&#39;);
<a name="line40"></a> *   goog.ui.media.PicasaAlbum.newControl(album).render();
<a name="line41"></a> * &lt;/pre&gt;
<a name="line42"></a> *
<a name="line43"></a> * picasa medias currently support the following states:
<a name="line44"></a> *
<a name="line45"></a> * &lt;ul&gt;
<a name="line46"></a> *   &lt;li&gt; {@link goog.ui.Component.State.DISABLED}: shows &#39;flash not available&#39;
<a name="line47"></a> *   &lt;li&gt; {@link goog.ui.Component.State.HOVER}: mouse cursor is over the album
<a name="line48"></a> *   &lt;li&gt; {@link goog.ui.Component.State.SELECTED}: flash album is shown
<a name="line49"></a> * &lt;/ul&gt;
<a name="line50"></a> *
<a name="line51"></a> * Which can be accessed by
<a name="line52"></a> *
<a name="line53"></a> * &lt;pre&gt;
<a name="line54"></a> *   picasa.setEnabled(true);
<a name="line55"></a> *   picasa.setHighlighted(true);
<a name="line56"></a> *   picasa.setSelected(true);
<a name="line57"></a> * &lt;/pre&gt;
<a name="line58"></a> *
<a name="line59"></a> *
<a name="line60"></a> * @supported IE6, FF2+, Safari. Requires flash to actually work.
<a name="line61"></a> *
<a name="line62"></a> * TODO(user): test on other browsers
<a name="line63"></a> */
<a name="line64"></a>
<a name="line65"></a>goog.provide(&#39;goog.ui.media.PicasaAlbum&#39;);
<a name="line66"></a>goog.provide(&#39;goog.ui.media.PicasaAlbumModel&#39;);
<a name="line67"></a>
<a name="line68"></a>goog.require(&#39;goog.ui.media.FlashObject&#39;);
<a name="line69"></a>goog.require(&#39;goog.ui.media.Media&#39;);
<a name="line70"></a>goog.require(&#39;goog.ui.media.MediaModel&#39;);
<a name="line71"></a>goog.require(&#39;goog.ui.media.MediaRenderer&#39;);
<a name="line72"></a>
<a name="line73"></a>
<a name="line74"></a>
<a name="line75"></a>/**
<a name="line76"></a> * Subclasses a goog.ui.media.MediaRenderer to provide a Picasa specific media
<a name="line77"></a> * renderer.
<a name="line78"></a> *
<a name="line79"></a> * This class knows how to parse picasa URLs, and render the DOM structure
<a name="line80"></a> * of picasa album players and previews. This class is meant to be used as a
<a name="line81"></a> * singleton static stateless class, that takes {@code goog.ui.media.Media}
<a name="line82"></a> * instances and renders it. It expects {@code goog.ui.media.Media.getModel} to
<a name="line83"></a> * return a well formed, previously constructed, object with a user and album
<a name="line84"></a> * fields {@see goog.ui.media.PicasaAlbum.parseUrl}, which is the data model
<a name="line85"></a> * this renderer will use to construct the DOM structure.
<a name="line86"></a> * {@see goog.ui.media.PicasaAlbum.newControl} for a example of constructing a
<a name="line87"></a> * control with this renderer.
<a name="line88"></a> *
<a name="line89"></a> * goog.ui.media.PicasaAlbum currently displays a picasa-made flash slideshow
<a name="line90"></a> * with the photos, but could possibly display a handwritten js photo viewer,
<a name="line91"></a> * in case flash is not available.
<a name="line92"></a> *
<a name="line93"></a> * This design is patterned after http://go/closure_control_subclassing
<a name="line94"></a> *
<a name="line95"></a> * It uses {@link goog.ui.media.FlashObject} to embed the flash object.
<a name="line96"></a> *
<a name="line97"></a> * @constructor
<a name="line98"></a> * @extends {goog.ui.media.MediaRenderer}
<a name="line99"></a> * @final
<a name="line100"></a> */
<a name="line101"></a>goog.ui.media.PicasaAlbum = function() {
<a name="line102"></a>  goog.ui.media.MediaRenderer.call(this);
<a name="line103"></a>};
<a name="line104"></a>goog.inherits(goog.ui.media.PicasaAlbum, goog.ui.media.MediaRenderer);
<a name="line105"></a>goog.addSingletonGetter(goog.ui.media.PicasaAlbum);
<a name="line106"></a>
<a name="line107"></a>
<a name="line108"></a>/**
<a name="line109"></a> * Default CSS class to be applied to the root element of components rendered
<a name="line110"></a> * by this renderer.
<a name="line111"></a> *
<a name="line112"></a> * @type {string}
<a name="line113"></a> */
<a name="line114"></a>goog.ui.media.PicasaAlbum.CSS_CLASS = goog.getCssName(&#39;goog-ui-media-picasa&#39;);
<a name="line115"></a>
<a name="line116"></a>
<a name="line117"></a>/**
<a name="line118"></a> * A static convenient method to construct a goog.ui.media.Media control out of
<a name="line119"></a> * a picasa data model. It sets it as the data model goog.ui.media.PicasaAlbum
<a name="line120"></a> * renderer uses, sets the states supported by the renderer, and returns a
<a name="line121"></a> * Control that binds everything together. This is what you should be using for
<a name="line122"></a> * constructing Picasa albums, except if you need finer control over the
<a name="line123"></a> * configuration.
<a name="line124"></a> *
<a name="line125"></a> * @param {goog.ui.media.PicasaAlbumModel} dataModel A picasa album data model.
<a name="line126"></a> * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper, used for
<a name="line127"></a> *     document interaction.
<a name="line128"></a> * @return {goog.ui.media.Media} A Control instance binded to the Picasa
<a name="line129"></a> *     renderer.
<a name="line130"></a> */
<a name="line131"></a>goog.ui.media.PicasaAlbum.newControl = function(dataModel, opt_domHelper) {
<a name="line132"></a>  var control = new goog.ui.media.Media(
<a name="line133"></a>      dataModel,
<a name="line134"></a>      goog.ui.media.PicasaAlbum.getInstance(),
<a name="line135"></a>      opt_domHelper);
<a name="line136"></a>  control.setSelected(true);
<a name="line137"></a>  return control;
<a name="line138"></a>};
<a name="line139"></a>
<a name="line140"></a>
<a name="line141"></a>/**
<a name="line142"></a> * Creates the initial DOM structure of the picasa album, which is basically a
<a name="line143"></a> * the flash object pointing to a flash picasa album player.
<a name="line144"></a> *
<a name="line145"></a> * @param {goog.ui.Control} c The media control.
<a name="line146"></a> * @return {Element} The DOM structure that represents the control.
<a name="line147"></a> * @override
<a name="line148"></a> */
<a name="line149"></a>goog.ui.media.PicasaAlbum.prototype.createDom = function(c) {
<a name="line150"></a>  var control = /** @type {goog.ui.media.Media} */ (c);
<a name="line151"></a>  var div = goog.ui.media.PicasaAlbum.superClass_.createDom.call(this, control);
<a name="line152"></a>
<a name="line153"></a>  var picasaAlbum =
<a name="line154"></a>      /** @type {goog.ui.media.PicasaAlbumModel} */ (control.getDataModel());
<a name="line155"></a>  var authParam =
<a name="line156"></a>      picasaAlbum.getAuthKey() ? (&#39;&amp;authkey=&#39; + picasaAlbum.getAuthKey()) : &#39;&#39;;
<a name="line157"></a>  var flash = new goog.ui.media.FlashObject(
<a name="line158"></a>      picasaAlbum.getPlayer().getUrl() || &#39;&#39;,
<a name="line159"></a>      control.getDomHelper());
<a name="line160"></a>  flash.addFlashVars(picasaAlbum.getPlayer().getVars());
<a name="line161"></a>  flash.render(div);
<a name="line162"></a>
<a name="line163"></a>  return div;
<a name="line164"></a>};
<a name="line165"></a>
<a name="line166"></a>
<a name="line167"></a>/**
<a name="line168"></a> * Returns the CSS class to be applied to the root element of components
<a name="line169"></a> * rendered using this renderer.
<a name="line170"></a> * @return {string} Renderer-specific CSS class.
<a name="line171"></a> * @override
<a name="line172"></a> */
<a name="line173"></a>goog.ui.media.PicasaAlbum.prototype.getCssClass = function() {
<a name="line174"></a>  return goog.ui.media.PicasaAlbum.CSS_CLASS;
<a name="line175"></a>};
<a name="line176"></a>
<a name="line177"></a>
<a name="line178"></a>
<a name="line179"></a>/**
<a name="line180"></a> * The {@code goog.ui.media.PicasaAlbum} media data model. It stores a required
<a name="line181"></a> * {@code userId} and {@code albumId} fields, sets the picasa album URL, and
<a name="line182"></a> * allows a few optional parameters.
<a name="line183"></a> *
<a name="line184"></a> * @param {string} userId The picasa userId associated with this album.
<a name="line185"></a> * @param {string} albumId The picasa albumId associated with this album.
<a name="line186"></a> * @param {string=} opt_authKey An optional authentication key, used on private
<a name="line187"></a> *     albums.
<a name="line188"></a> * @param {string=} opt_caption An optional caption of the picasa album.
<a name="line189"></a> * @param {string=} opt_description An optional description of the picasa album.
<a name="line190"></a> * @param {boolean=} opt_autoplay Whether to autoplay the slideshow.
<a name="line191"></a> * @constructor
<a name="line192"></a> * @extends {goog.ui.media.MediaModel}
<a name="line193"></a> * @final
<a name="line194"></a> */
<a name="line195"></a>goog.ui.media.PicasaAlbumModel = function(userId,
<a name="line196"></a>                                          albumId,
<a name="line197"></a>                                          opt_authKey,
<a name="line198"></a>                                          opt_caption,
<a name="line199"></a>                                          opt_description,
<a name="line200"></a>                                          opt_autoplay) {
<a name="line201"></a>  goog.ui.media.MediaModel.call(
<a name="line202"></a>      this,
<a name="line203"></a>      goog.ui.media.PicasaAlbumModel.buildUrl(userId, albumId),
<a name="line204"></a>      opt_caption,
<a name="line205"></a>      opt_description,
<a name="line206"></a>      goog.ui.media.MediaModel.MimeType.FLASH);
<a name="line207"></a>
<a name="line208"></a>  /**
<a name="line209"></a>   * The Picasa user id.
<a name="line210"></a>   * @type {string}
<a name="line211"></a>   * @private
<a name="line212"></a>   */
<a name="line213"></a>  this.userId_ = userId;
<a name="line214"></a>
<a name="line215"></a>  /**
<a name="line216"></a>   * The Picasa album id.
<a name="line217"></a>   * @type {string}
<a name="line218"></a>   * @private
<a name="line219"></a>   */
<a name="line220"></a>  this.albumId_ = albumId;
<a name="line221"></a>
<a name="line222"></a>  /**
<a name="line223"></a>   * The Picasa authentication key, used on private albums.
<a name="line224"></a>   * @type {?string}
<a name="line225"></a>   * @private
<a name="line226"></a>   */
<a name="line227"></a>  this.authKey_ = opt_authKey || null;
<a name="line228"></a>
<a name="line229"></a>  var authParam = opt_authKey ? (&#39;&amp;authkey=&#39; + opt_authKey) : &#39;&#39;;
<a name="line230"></a>
<a name="line231"></a>  var flashVars = {
<a name="line232"></a>    &#39;host&#39;: &#39;picasaweb.google.com&#39;,
<a name="line233"></a>    &#39;RGB&#39;: &#39;0x000000&#39;,
<a name="line234"></a>    &#39;feed&#39;: &#39;http://picasaweb.google.com/data/feed/api/user/&#39; +
<a name="line235"></a>        userId + &#39;/album/&#39; + albumId + &#39;?kind=photo&amp;alt=rss&#39; + authParam
<a name="line236"></a>  };
<a name="line237"></a>  flashVars[opt_autoplay ? &#39;autoplay&#39; : &#39;noautoplay&#39;] = &#39;1&#39;;
<a name="line238"></a>
<a name="line239"></a>  var player = new goog.ui.media.MediaModel.Player(
<a name="line240"></a>      &#39;http://picasaweb.google.com/s/c/bin/slideshow.swf&#39;, flashVars);
<a name="line241"></a>
<a name="line242"></a>  this.setPlayer(player);
<a name="line243"></a>};
<a name="line244"></a>goog.inherits(goog.ui.media.PicasaAlbumModel, goog.ui.media.MediaModel);
<a name="line245"></a>
<a name="line246"></a>
<a name="line247"></a>/**
<a name="line248"></a> * Regular expression used to extract the picasa username and albumid out of
<a name="line249"></a> * picasa URLs.
<a name="line250"></a> *
<a name="line251"></a> * Copied from http://go/markdownlite.js,
<a name="line252"></a> * and {@link PicasaWebExtractor.xml}.
<a name="line253"></a> *
<a name="line254"></a> * @type {RegExp}
<a name="line255"></a> * @private
<a name="line256"></a> * @const
<a name="line257"></a> */
<a name="line258"></a>goog.ui.media.PicasaAlbumModel.MATCHER_ =
<a name="line259"></a>    /https?:\/\/(?:www\.)?picasaweb\.(?:google\.)?com\/([\d\w\.]+)\/([\d\w_\-\.]+)(?:\?[\w\d\-_=&amp;amp;;\.]*&amp;?authKey=([\w\d\-_=;\.]+))?(?:#([\d]+)?)?/im;
<a name="line260"></a>
<a name="line261"></a>
<a name="line262"></a>/**
<a name="line263"></a> * Gets a {@code picasaUrl} and extracts the user and album id.
<a name="line264"></a> *
<a name="line265"></a> * @param {string} picasaUrl A picasa album URL.
<a name="line266"></a> * @param {string=} opt_caption An optional caption of the picasa album.
<a name="line267"></a> * @param {string=} opt_description An optional description of the picasa album.
<a name="line268"></a> * @param {boolean=} opt_autoplay Whether to autoplay the slideshow.
<a name="line269"></a> * @return {goog.ui.media.PicasaAlbumModel} The picasa album data model that
<a name="line270"></a> *     represents the picasa URL.
<a name="line271"></a> * @throws exception in case the parsing fails
<a name="line272"></a> */
<a name="line273"></a>goog.ui.media.PicasaAlbumModel.newInstance = function(picasaUrl,
<a name="line274"></a>                                                      opt_caption,
<a name="line275"></a>                                                      opt_description,
<a name="line276"></a>                                                      opt_autoplay) {
<a name="line277"></a>  if (goog.ui.media.PicasaAlbumModel.MATCHER_.test(picasaUrl)) {
<a name="line278"></a>    var data = goog.ui.media.PicasaAlbumModel.MATCHER_.exec(picasaUrl);
<a name="line279"></a>    return new goog.ui.media.PicasaAlbumModel(
<a name="line280"></a>        data[1], data[2], data[3], opt_caption, opt_description, opt_autoplay);
<a name="line281"></a>  }
<a name="line282"></a>  throw Error(&#39;failed to parse user and album from picasa url: &#39; + picasaUrl);
<a name="line283"></a>};
<a name="line284"></a>
<a name="line285"></a>
<a name="line286"></a>/**
<a name="line287"></a> * The opposite of {@code newInstance}: takes an {@code userId} and an
<a name="line288"></a> * {@code albumId} and builds a URL.
<a name="line289"></a> *
<a name="line290"></a> * @param {string} userId The user that owns the album.
<a name="line291"></a> * @param {string} albumId The album id.
<a name="line292"></a> * @return {string} The URL of the album.
<a name="line293"></a> */
<a name="line294"></a>goog.ui.media.PicasaAlbumModel.buildUrl = function(userId, albumId) {
<a name="line295"></a>  return &#39;http://picasaweb.google.com/&#39; + userId + &#39;/&#39; + albumId;
<a name="line296"></a>};
<a name="line297"></a>
<a name="line298"></a>
<a name="line299"></a>/**
<a name="line300"></a> * Gets the Picasa user id.
<a name="line301"></a> * @return {string} The Picasa user id.
<a name="line302"></a> */
<a name="line303"></a>goog.ui.media.PicasaAlbumModel.prototype.getUserId = function() {
<a name="line304"></a>  return this.userId_;
<a name="line305"></a>};
<a name="line306"></a>
<a name="line307"></a>
<a name="line308"></a>/**
<a name="line309"></a> * Gets the Picasa album id.
<a name="line310"></a> * @return {string} The Picasa album id.
<a name="line311"></a> */
<a name="line312"></a>goog.ui.media.PicasaAlbumModel.prototype.getAlbumId = function() {
<a name="line313"></a>  return this.albumId_;
<a name="line314"></a>};
<a name="line315"></a>
<a name="line316"></a>
<a name="line317"></a>/**
<a name="line318"></a> * Gets the Picasa album authentication key.
<a name="line319"></a> * @return {?string} The Picasa album authentication key.
<a name="line320"></a> */
<a name="line321"></a>goog.ui.media.PicasaAlbumModel.prototype.getAuthKey = function() {
<a name="line322"></a>  return this.authKey_;
<a name="line323"></a>};
</pre>


</body>
</html>
